" 修复Neovim右键点击报错的脚本
" 运行方法: 在Neovim中执行 :source k:/winkit/root/fix_nvim_right_click.vim

lua << EOF
  -- 重新定义enable_ctx_menu函数，完全避免任何可能的错误
  local function fixed_enable_ctx_menu()
    -- 只做最基本的操作，确保不会出错
    local status, _ = pcall(function()
      -- 禁用所有菜单项
      vim.cmd([[
        amenu disable PopUp.Go\ to\ definition
        amenu disable PopUp.Open\ in\ web\ browser
        amenu disable PopUp.Show\ Diagnostics
        amenu disable PopUp.Show\ All\ Diagnostics
        amenu disable PopUp.Configure\ Diagnostics
      ]])
    end)
    return true
  end

  -- 重新注册MenuPopup自动命令
  local nvim_popupmenu_augroup = vim.api.nvim_create_augroup('nvim.popupmenu', { clear = true })
  vim.api.nvim_create_autocmd('MenuPopup', {
    pattern = '*',
    group = nvim_popupmenu_augroup,
    desc = 'Mouse popup menu (fixed)',
    callback = function()
      fixed_enable_ctx_menu()
    end,
  })

  print('右键点击修复已应用！')
EOF